package com.gla.controller;

import com.github.pagehelper.PageInfo;
import com.gla.commom.Result;
import com.gla.entity.Commodity;
import com.gla.entity.Shop;
import com.gla.service.FYHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/shop")
public class ShopController {
    @Autowired
    FYHService FYHService;

    @GetMapping("/getallshop")
    public Result getallshop() {
        List<Shop> list = FYHService.selectAllShop();
        PageInfo pageInfo = new PageInfo(list);
        return Result.succeed(pageInfo);
    }

    @GetMapping("/getshopmore")
    public Result getshopmore(Integer id) {
        return Result.succeed(FYHService.selectShopMore(id));
    }

    @GetMapping("/getshoppoint")
    public Result getshoppoint(Integer id) {
        return Result.succeed(FYHService.selectEvaluationByPoint(id));
    }

    @GetMapping("/delshop")
    public Result delshop(Integer id){
        return Result.succeed(new PageInfo(FYHService.delShopById(id)));
    }

    @PutMapping("/updateshop")
    public Result updateshop(@RequestBody Shop shop){
        return Result.succeed(new PageInfo(FYHService.updateShopById(shop)));
    }

    @GetMapping("/getoneshop")
    public Result getoneshop(Integer id){
        return Result.succeed(FYHService.getOneShop(id));
    }

    @PutMapping("/insertshop")
    public Result insertshop(@RequestBody Shop shop){
        return Result.succeed(new PageInfo(FYHService.insertShop(shop)));
    }

    @GetMapping("/delcommodity")
    public Result delcommodity(Integer id, Integer sid){
        return Result.succeed(FYHService.delCommodityById(id, sid));
    }

    @PutMapping("/updatecommodity")
    public Result updatecommodity(@RequestBody Commodity commodity){
        return Result.succeed(FYHService.updateCommodity(commodity));
    }

    @GetMapping("/getonecommodity")
    public Result getonecommodity(Integer id){
        return Result.succeed(FYHService.getOneCommodity(id));
    }

    @PutMapping("/insertcommodity")
    public Result insertcommodity(@RequestBody Commodity commodity){
        return Result.succeed(FYHService.insertCommodity(commodity));
    }
}
